package com.bootdo.shop.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.alibaba.fastjson.JSON;
import com.bootdo.shop.dao.ProductDao;
import com.bootdo.shop.domain.CategoryDO;
import com.bootdo.shop.domain.ProductDO;
import com.bootdo.shop.service.CategoryService;
import com.bootdo.shop.service.ProductService;


@RunWith(SpringRunner.class)
@SpringBootTest
public class ShopTestController {
	
	@Autowired
	private ProductDao productDao;
	
	@Autowired
	private CategoryService categoryService;
	@Autowired 
	private ProductService productService;
	
	
	@Test
	public void indexPtypelist() {
		
		
		CategoryDO c = new CategoryDO();
		c.setShowInHot(1);
		
		 Map<String, Object> params =new HashMap<String, Object>();
		 params.put("showInHot", 1);
		List<CategoryDO> listall = categoryService.list(params);
		
		for (CategoryDO categoryDO : listall) {
			
			List<CategoryDO> blist = categoryService.getCategoryBrotherList(categoryDO.getCategoryId());
			Map<String, Object> map =new HashMap<String, Object>();
			map.put("categoryId", categoryDO.getCategoryId());
			List<ProductDO> plist =productService.list(map);
			
			categoryDO.setClist(blist);
			categoryDO.setProductList(plist);
			
		}
		
		
		System.out.println(JSON.toJSONString(listall));
	}
	
	
	@Test
	public void list() {
		
		/*ProductDO p = new ProductDO();
		p.setCategoryId(37l);*/
		 Map<String, Object> params =new HashMap<String, Object>();
		 params.put("categoryId", 37l);
		List<ProductDO> list = productDao.list(params);
		/*Category c = categoryMapper.getUpper(2l);
		//Category c = iCategoryService.selectById(2l);
		
		System.out.println(JSON.toJSONString(c));*/
		
		System.out.println(JSON.toJSONString(list));
		
	}
	
	
	
}
